package com.mywork.mvpkodeinxml.base.presenter

import android.content.Context
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.mywork.common.utils.isNetWorkAvailable
import com.mywork.mvpkodeinxml.base.view.BaseView
import org.kodein.di.Kodein
import org.kodein.di.generic.instance

abstract class BasePresenter<T : BaseView>(kodein: Kodein) : IBasePresenter {

    //inject
    open val mView: BaseView by kodein.instance()

    //inject
    val lifecycleOwner: LifecycleOwner by kodein.instance()

    //inject
    val context: Context by kodein.instance()

    fun checkNetwork(): Boolean {
        if (context.isNetWorkAvailable()) {
            return true
        }
        mView.showToast("网络不可用")
        return false
    }

    //绑定view生命周期
    override fun onCreate(owner: LifecycleOwner) {

    }

    //绑定view生命周期
    override fun onDestroy(owner: LifecycleOwner) {

    }

    //绑定view生命周期
    override fun onLifecycleChanged(owner: LifecycleOwner, event: Lifecycle.Event) {

    }
}